<extend name="Layout/application"/>

<block name="content">
    <div class="row">
        <div class="col-md-12">

            <div class="row">
                <div class="col-md-8">
                    <div class="page-header">
                        <h1>系统首页</h1>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-10">
                    <div class="panel panel-default">
                        <div class="panel-heading">文件上传</div>
                        <div class="panel-body">
                            <form class="form-horizontal" role="form" method="post" action="{{:U('do_upload',array('path'=>$path))}}" enctype="multipart/form-data">
                                <div class="form-group">
                                    <div class="col-sm-10 col-lg-offset-2">
                                        <label for="exampleInputFile">选择附件</label>
                                        <input type="file" name="file[]" id="exampleInputFile">
                                    </div>
                                    <div class="col-sm-10 col-lg-offset-2">
                                        <label for="exampleInputFile1">选择附件</label>
                                        <input type="file" name="file[]" id="exampleInputFile1">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button type="submit" class="btn btn-primary">上 传</button>
                                        <button type="button" class="btn btn-success return">返回</button>
                                    </div>
                                </div>
                                <!--<div class="form-group">
                                    <label class="col-sm-2 control-label">图片</label>
                                    <div class="col-sm-10">
                                        <input type="text" id="thumb" class="span5 form-control" name="thumb">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-sm-10 col-lg-offset-2">
                                        <button type="button" class="btn btn-success"
                                                onclick="BrowseServer('thumb','img_show')">上传
                                        </button>
                                        <button type="button" class="btn btn-danger delete_thumb">删除</button>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">预览</label>
                                    <div class="col-sm-10">
                                        <img src="" id="img_show" style="max-height: 120px;"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-sm-10 col-sm-offset-2">
                                        <button type="button" class="btn btn-primary" id="more_files">添加更多
                                        </button>
                                    </div>
                                </div>
                                <div class="files">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">附件（1）</label>
                                        <div class="col-sm-10">
                                            <input type="text" id="file1" class="span5 form-control"
                                                   name="file[]">
                                        </div>
                                        <div class="col-sm-10 col-lg-offset-2">
                                            <button type="button" class="btn btn-success"
                                                    onclick="BrowseServerFile('file1')">上传
                                            </button>
                                            <button type="button" class="btn btn-danger deletefile1">删除</button>
                                        </div>
                                    </div>
                                </div>-->
                            </form>

                        </div>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="list-group">
                        <a href="javascript: void 0;"
                           class="list-group-item list-group-item-info sort_category" data-toggle="modal"
                           data-target="#myModal">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 新增 (add)
                        </a>

                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_category">
                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 排序 (sort)
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>


</block>
<block name="js">
    <script type="text/javascript" src="__PUBLIC__/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="__PUBLIC__/ckfinder/ckfinder.js"></script>
    <script>


        //上传图片
        function BrowseServer(thumb, img_show) {
            var finder = new CKFinder();

            //当选中图片时执行的函数
            finder.selectActionFunction = function (fileUrl) {
                $("#" + thumb).val(fileUrl);
                $("#" + img_show).attr("src", "" + fileUrl + "");
            }
            finder.popup();//调用窗口
        }
        //上传附件
        function BrowseServerFile(file) {
            var finder = new CKFinder();

            //当选中图片时执行的函数
            finder.selectActionFunction = function (fileUrl) {
                $("#" + file).val(fileUrl);
            }
            finder.popup();//调用窗口
        }
        $(function () {
            var index = 2;
            $("#more_files").click(function () {
                var length = $(".files").children().length;
                if (length == 5) {
                    alert("只能上传5个附件！")
                    return false;
                }
                var html = '<div class="form-group"> ' +
                        '<label class="col-sm-2 control-label">附件（' + index + '）</label> ' +
                        '<div class="col-sm-10"> ' +
                        '<input type="text" id="file' + index + '" class="span5 form-control"' +
                        'name="file[]"> ' +
                        '</div> ' +
                        '<div class="col-sm-10 col-lg-offset-2"> ' +
                        '<button type="button" class="btn btn-success"' +
                        'onclick="BrowseServerFile(\'file' + index + '\')">上传 ' +
                        '</button> ' +
                        '<button type="button" class="btn btn-danger delete_file">删除</button> ' +
                        '</div> ' +
                        '</div>';
                index++;


                $(".files").append(html);
            });

            //删除第一个附件
            $(".deletefile1").click(function () {
                $(this).parents(".form-group").find("input").val('');
            });

            //动态删除其他附件
            $(document).on('click', '.delete_file', function () {
                $(this).parents(".form-group").remove();
            })

            $(".delete_thumb").click(function () {
                $("#thumb").val('');
                $("#img_show").attr('src', '')
            })

            $(".return").click(function () {
                location.href=document.referrer;
            })
        })
    </script>
</block>